/*
 * jAutomation: Portable input Automation 
 * Copyright (C) 2012 Dominik Hensler.  
 * http://code.google.com/p/jautomation
 * 
 * This Program uses JNativeHook by Alexander Barker:
 * JNativeHook: Global keyboard and mouse hooking for Java.
 * Copyright (C) 2006-2012 Alexander Barker.  All Rights Received.
 * http://code.google.com/p/jnativehook/
 *
 * 
 * This file is part of JAutomation.

 * JAutomation is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * JAutomation is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with JAutomation.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.jautomation.core;

import java.awt.Point;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

/**
 *
 * @author Dominik Hensler
 */
public class ControlReceiver {
    Robot _processor;
    PchangeThread _detector;
    public ControlReceiver(Robot processor, PchangeThread detector){      
        this._processor= processor;
        this._detector=detector;     
    }
    public void delay(String code){
        this._processor.delay(Integer.valueOf(code));
    }    

    public synchronized void pixelDetectorOff(MainContext stateInformation) {
            if (!this._detector.isThreadInterrupted()) {                
                System.out.println("stopping thread");
                this._detector.haltThread();
            }
    }

    public synchronized void pixelDetectorOn(MainContext stateInformation) {           
         this._detector.resumeThread();
    }

    public synchronized void setScanMode(int scanmode, MainContext stateInformation) {
         this._detector.setContextSnapshot(stateInformation.getCommandArray());
         this._detector.setFirstRun(true);
         this._detector.setScanMode(scanmode);        
    }

    public void setCurrentPoint(Point currentPosition) {
        this._detector.setCurrentPoint(currentPosition);
    }

    public void findPixel(double[] cieLabColor) {
        this._detector.findPixel(cieLabColor);
    }

    public void exit() {
        this._processor.keyRelease(KeyEvent.VK_SHIFT);
        this._processor.keyRelease(InputEvent.BUTTON1_MASK);
        this._processor.keyRelease(InputEvent.BUTTON3_MASK);
        System.exit(0);
    }
}
